'''
0 offer
'''
# -*- coding:utf-8 -*-
class Solution:
    def NumberOf1Between1AndN_Solution(self, n):
        # write code here
        res = ''
        for i in range(n):
            res += str(i)
        res += str(n)
        num = res.count('1')
        return num

'''
all offers
'''
# -*- coding:utf-8 -*-
class Solution:
    def NumberOf1Between1AndN_Solution(self, n):
        # write code here
        ones = 0
        m = 1
        while m <= n:
            a = n/m
            b = n%m
            ones += (a + 8) / 10 * m + (a % 10 == 1) * (b + 1);
            m *= 10
        return ones